using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Presenters;
using Dominio;
using Exeptions;

public partial class LogIn : System.Web.UI.Page
{
    private LogInPresenter presenter;
    protected void Page_Load(object sender, EventArgs e)
    {
        presenter = new LogInPresenter();
    }
    protected void Submit1_Click(object sender, EventArgs e)
    {
        try
        {
            User user = presenter.logIn(mailtxt.Text, passtxt.Text);
            if (user != null)
            {
                Session["user"] = user;
                if (user.Role.isTester(user))
                {
                    Tester tester = (Tester)user;
                    if (tester.State != "active")
                    {
                        Response.Redirect("ErrorPage.aspx?errorMessage=USUARIO NO ACTIVO");
                    }
                }
                Response.Redirect(user.Role.Home);
            }
            else
            {
                Response.Redirect("ErrorPage.aspx?errorMessage=USUARIO O PASSWORD ERROR");
            }

        }
        catch (DvhExeption exep)
        {
            Response.Redirect("ErrorPage.aspx?errorMessage=" + exep.Message);
        }
    }

    protected override void InitializeCulture()
    {
        if (Request.QueryString["lang"] != null)
        {
            UICulture = Request.QueryString["lang"];
            Session["lang"] = UICulture;
        }
        base.InitializeCulture();

    }
}
